package com.fishy.chat.action;

import com.fishy.chat.model.entity.Message;
import io.netty.channel.Channel;
import io.netty.channel.ChannelId;
import io.netty.channel.group.ChannelGroup;
import io.netty.channel.group.DefaultChannelGroup;
import io.netty.util.concurrent.GlobalEventExecutor;
import lombok.extern.slf4j.Slf4j;

/**
 * @author anlingyi
 * @date 2020/8/14
 */
@Slf4j
public class ChannelAction {

    private static final ChannelGroup GROUP = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE);

    public static void add(Channel channel) {
        GROUP.add(channel);
    }

    public static void send(Message message) {
        GROUP.writeAndFlush(message);
    }

    public static boolean checkLogin(ChannelId channelId) {
        return GROUP.find(channelId) != null;
    }
}
